package sskj.regulatory.data.mapper

import sskj.regulatory.data.response.camera.CameraEngResponse
import sskj.regulatory.data.response.camera.CameraResponse
import sskj.regulatory.data.response.session.BingDingResponse
import sskj.regulatory.data.response.session.UserResponse
import sskj.regulatory.domain.entity.sitevideo.Site
import sskj.regulatory.domain.entity.sitevideo.SiteVideo
import sskj.regulatory.domain.entity.user.BingDingEntity
import sskj.regulatory.domain.entity.user.UserEntity
import sskj.regulatory.ribble.presentation.utils.extensions.emptyString
import java.util.*


class Mapper {

    fun tanslate(roleId: String, bingDingResponseList: List<BingDingResponse>): BingDingEntity? {
        return bingDingResponseList.asSequence()
                .map {
                    translate(it)
                }.singleOrNull {
                    it.roleId == roleId
                }
    }

    fun translate(userResponse: UserResponse?): UserEntity {
        return UserEntity(userResponse?.username ?: emptyString, "", userResponse?.username
                ?: emptyString, "", "", "", Date())
    }

    @JvmName("translateSiteVideoEntity")
    fun translate(cameraEngResponseList: List<CameraEngResponse.Data>): List<Site> {
        return cameraEngResponseList
                .asSequence()
                .map {
                    translate(it)
                }
                .toList()
    }

    fun translate(bingDingResponse: BingDingResponse): BingDingEntity {
        return BingDingEntity(bingDingResponse.id, bingDingResponse.userId, bingDingResponse.roleId, "",
                bingDingResponse.userName, bingDingResponse?.name ?: "", bingDingResponse?.pwd
                ?: "", "", "")
    }

    private fun translate(cameraEngResponse: CameraEngResponse.Data): Site {
        return Site(cameraEngResponse.name, cameraEngResponse.code, cameraEngResponse.xxjd,
                cameraEngResponse.bjrq, cameraEngResponse.jsdw, cameraEngResponse.sgdw,
                cameraEngResponse.jldw, cameraEngResponse.jsgm, cameraEngResponse.picpriviewurl
                , cameraEngResponse.cams?.asSequence()?.map { translate(it) }?.toList())
    }

    private fun translate(cameraResponse: CameraResponse): SiteVideo {
        return SiteVideo(cameraResponse.sysCode, cameraResponse.cameraName, cameraResponse.cameraId)

    }

}